#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>

int main(int argc,char** argv)
{
  pid_t pid;
  int fd[2];
  int ret = pipe(fd);
  pid = fork();
  if(ret < 0)
  {
    fprintf(stderr,"pipe is fail\n");
    return -1;
  }
  if(pid > 0)
  {
    close(fd[1]);
    waitpid(pid,NULL,0);
    dup2(fd[0],STDIN_FILENO);
    execlp("wc","wc","-w",NULL);
    close(fd[0]);
  }

  if(pid == 0)
  {
    printf("I am a child\n");
    close(fd[0]);
    dup2(fd[1],STDOUT_FILENO);
    execlp("ls","ls",NULL);
    close(fd[1]);
  }
    
  return 0;
}
